<?php 
class C_groups extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('m_groups');
		checkLogin();
	}
	
	function index(){
		$task = $this->input->post('task');
		switch($task){
			case 'LIST' :
				$this->getlist();
				break;
			case 'SAVE' :
				$this->insert();
				break;
			case 'EDIT' :
				$this->edit();
				break;
			case 'DELETE' :
				$this->delete();
				break;
			default : 
				$this->load->view('v_groups');
		}
	}
		
	function getlist(){
		$filter =  isset($_POST['query']) ? @$_POST['query'] : "";
		$offset = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$limit  = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		echo $this->m_groups->getlist($filter,$offset,$limit);
	}
	
	function insert(){
		$data = array('group_name' => $this->input->post('group_name'),
					  'group_desc' => $this->input->post('keterangan'));
		$this->m_groups->insert($data);
		$message = 1;
		echo $message;
	}
	
	function edit(){
		$group_id = $this->input->post('group_id');
		$data = array('group_name' => $this->input->post('group_name'),
					  'group_desc' => $this->input->post('keterangan'));
		$this->m_groups->update($group_id,$data);
		$message = 1;
		echo $message;
	}
	
	function delete(){
		$group_id = $this->input->post('group_id');
		$data    = array('group_active '=> 'T');
		$this->db->where('group_id',2)->update('s_usergroups',$data);
		$message = 1;
		echo $message;
	}
}